package server.session.handler;

import server.session.UserSession;
import unit.request.AddContactRequest;
import unit.request.Request;
import unit.response.AddedToContactListMessage;
import unit.response.ServerMessage;

/**
 * @author Yuri Denison
 * @since 08.08.11
 */
public class AddContactRequestHandler implements RequestHandler {

    @Override
    public void handleRequest(Request request, UserSession userSession) {
        AddContactRequest addContactRequest = (AddContactRequest) request;
        ServerMessage message = new AddedToContactListMessage(userSession.getSession(), userSession.getUserId());
        userSession.getDataStorage().addToContactList(userSession.getUserId(), addContactRequest.getUserId());
        userSession.getCommunicator().send(addContactRequest.getUserId(), message);
    }
}
